package com.wgzx.modbus.entity.request;

import com.wgzx.modbus.entity.ModbusReq;

import static com.wgzx.modbus.constant.FunctionCode.WRITE_SINGLE_REGISTER;
import static com.wgzx.modbus.util.ModbusUtil.validateRange;

/**
 * 写单个寄存器 <br/>
 * 功能码：0x06 <br/>
 * 寄存器地址：2个字节0x0000至0xFFFF <br/>
 * 寄存器值：2个字节0x0000至0xFFFF <br/>
 *
 * @author gexin
 */
public class WriteSingleRegisterRequest extends ModbusReq {

    public WriteSingleRegisterRequest(int address, int value) {
        super(WRITE_SINGLE_REGISTER, address, value);
        validateRange(address, "address", 0x00, 0xFFFF);
        validateRange(value, "value", 0x00, 0xFFFF);
    }

    @Override
    public String toString() {
        return "WriteSingleInputRegister{" + "registerAddress=" + address + ", registerValue=" + value + '}';
    }
}
